<?php

namespace app\common\model\fittings;

use think\Model;


class Aftersale extends Model
{

    

    

    // 表名
    protected $name = 'fittings_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'paytime_text',
        'pay_type_text',
        'deliver_text',
        'status_text',
        'sale_status_text',
        'refund_status_text',
        'sendtime_text',
        'taketime_text'
    ];
    

    
    public function getPayTypeList()
    {
        return ['1' => __('Pay_type 1')];
    }

    public function getDeliverList()
    {
        return ['1' => __('Deliver 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '-1' => __('Status -1')];
    }

    public function getSaleStatusList()
    {
        return ['0' => __('Sale_status 0'), '1' => __('Sale_status 1'), '2' => __('Sale_status 2')];
    }

    public function getRefundStatusList()
    {
        return [ '1' => __('Refund_status 1'), '2' => __('Refund_status 2')];
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDeliverTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deliver']) ? $data['deliver'] : '');
        $list = $this->getDeliverList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSaleStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sale_status']) ? $data['sale_status'] : '');
        $list = $this->getSaleStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRefundStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
        $list = $this->getRefundStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSendtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sendtime']) ? $data['sendtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTaketimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['taketime']) ? $data['taketime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setSendtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setTaketimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function fittings()
    {
        return $this->belongsTo('app\common\model\Fittings', 'm_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
